#include "DhData.h"

#include <float.h>
#include <limits.h>

#include "ComDefine.h"

bool CDhData::IsCommNormal()
{
    return (0 == m_uCommState);
}

bool CDhData::IsCommFault()
{
    return (1 == m_uCommState);
}

bool CDhData::IsRunning()
{
    return (0 == m_uRunState);
}

bool CDhData::IsStopped()
{
    return (1 == m_uRunState);
}

bool CDhData::IsFault()
{
    return (1 == m_uFaultState);
}

bool CDhData::IsNoFault()
{
    return (0 == m_uFaultState);
}

bool CDhData::IsAlarm()
{
    return (1 == m_uAlarmState);
}

bool CDhData::IsNoAlarm()
{
    return (0 == m_uAlarmState);
}

bool CDhData::IsOpening()
{
    return (1 == m_uSwitchState);
}

bool CDhData::IsClosed()
{
    return (0 == m_uSwitchState);
}

//获取***的显示文本
QString CDhData::GetCommStateText()
{
    if (0xFFFF == m_uCommState)
    {
        return QObject::tr("---");
    }
    else if (1 == m_uCommState)
    {
        return QObject::tr("故障");
    }
    else
    {
        return QObject::tr("正常");
    }
}

void CDhData::InitToInvalid()
{
    InitToValue(0xFFFF, FLT_MAX);
}

void CDhData::InitToZero()
{
    InitToValue(0, 0.0);
}

void CDhData::InitToValue(quint16 uvalue, float fvalue)
{
    m_uCommState = uvalue;
    for (int i = 0; i < ARRAYSIZE(m_uRev); ++i)
    {
        m_uRev[i] = uvalue;
    }

    for (int i = 0; i < ARRAYSIZE(m_fRev); ++i)
    {
        m_fRev[i] = fvalue;
    }

    //转发的100个UINT16数据
    m_uRunState = uvalue;
    m_uFaultState = uvalue;
    m_uAlarmState = uvalue;
    m_uSwitchState = uvalue;
    m_uCtrlTempType = uvalue;        //控温方式

    m_uCtrlHumiType = uvalue;        //控湿方式
    m_uCtrlTempManualSwitch = uvalue; //控温手动开关
    m_uCtrlHumiManualSwitch = uvalue; //控湿手动开关
    for (int i = 0; i < ARRAYSIZE(m_uData); ++i)
    {
        m_uData[i] = uvalue;
    }

    //转发的100个FLOAT数据
    m_fInsideTemp = fvalue;
    m_fInsideHumi = fvalue;
    m_fOutsideTemp = fvalue;
    m_fOutsideHumi = fvalue;
    m_fCtrlTempStartValue = fvalue;    //控温开启值

    m_fCtrlTempStopValue = fvalue;     //控温停止值
    m_fCtrlTempDiffValue = fvalue;     //控温回差值
    m_fCtrlHumiStartValue = fvalue;    //控湿开启值
    m_fCtrlHumiStopValue = fvalue;     //控湿停止值
    m_fCtrlHumiDiffValue = fvalue;     //控湿回差值

    m_fTempAlarmUpLimit = fvalue;      //温度报警上限值
    m_fTempAlarmDownLimit = fvalue;    //温度报警下限值
    m_fPointTempStartValue = fvalue;   //露点温度启动值
    m_fPointTempStopValue = fvalue;    //露点温度停止值
    m_fPointTempDiffValue = fvalue;    //露点温度回差值

    m_fHeaterStartTemp = fvalue;       //加热器启动温度
    m_fHeaterStopTemp = fvalue;        //加热器停止温度
    m_fHeaterDiffTemp = fvalue;        //加热器回差温度
    m_fDryerStartHumi = fvalue;        //除湿器启动湿度
    m_fDryerStopHumi = fvalue;         //除湿器停止湿度

    m_fDryerDiffHumi = fvalue;         //除湿器回差湿度
    m_fFanStartTemp = fvalue;          //排风启动温度
    m_fFanStopTemp = fvalue;           //排风停止温度
    m_fFanDiffTemp = fvalue;           //排风回差温度
    m_fMonitorMaxTemp = fvalue;        //监控下发最大温度,单位为℃

    m_fMonitorMinTemp = fvalue;        //监控下发最小温度,单位为℃
    m_fMonitorAvgTemp = fvalue;        //监控下发平均温度,单位为℃
    m_fVolAlarmUpLimit = fvalue;       //电压告警高限,单位为V
    m_fVolAlarmDownLimit = fvalue;     //电压告警低限,单位为V
    for (int i = 0; i < ARRAYSIZE(m_fData); ++i)
    {
        m_fData[i] = fvalue;
    }

    m_fSetTempStart = fvalue;
    m_fSetTempStartCopy = fvalue;
    m_fSetTempStop = fvalue;
    m_fSetTempStopCopy = fvalue;
    m_fSetTempDiff = fvalue;
    m_fSetTempDiffCopy = fvalue;
    m_fSetHumiStart = fvalue;
    m_fSetHumiStartCopy = fvalue;
    m_fSetHumiStop = fvalue;
    m_fSetHumiStopCopy = fvalue;
    m_fSetHumiDiff = fvalue;
    m_fSetHumiDiffCopy = fvalue;

    m_fSetCtrlTempStartValue = fvalue;    //控温开启值
    m_fSetCtrlTempStartValueCopy = fvalue;
    m_fSetCtrlTempStopValue = fvalue;     //控温停止值
    m_fSetCtrlTempStopValueCopy = fvalue;
    m_fSetCtrlTempDiffValue = fvalue;     //控温回差值
    m_fSetCtrlTempDiffValueCopy = fvalue;
    m_fSetCtrlHumiStartValue = fvalue;    //控湿开启值
    m_fSetCtrlHumiStartValueCopy = fvalue;

    m_fSetCtrlHumiStopValue = fvalue;     //控湿停止值
    m_fSetCtrlHumiStopValueCopy = fvalue;
    m_fSetCtrlHumiDiffValue = fvalue;     //控湿回差值
    m_fSetCtrlHumiDiffValueCopy = fvalue;
    m_fSetTempAlarmUpLimit = fvalue;      //温度报警上限值
    m_fSetTempAlarmUpLimitCopy = fvalue;
    m_fSetTempAlarmDownLimit = fvalue;    //温度报警下限值
    m_fSetTempAlarmDownLimitCopy = fvalue;
    m_fSetPointTempStartValue = fvalue;   //露点温度启动值
    m_fSetPointTempStartValueCopy = fvalue;

    m_fSetPointTempStopValue = fvalue;    //露点温度停止值
    m_fSetPointTempStopValueCopy = fvalue;
    m_fSetPointTempDiffValue = fvalue;    //露点温度回差值
    m_fSetPointTempDiffValueCopy = fvalue;
    m_fSetHeaterStartTemp = fvalue;       //加热器启动温度
    m_fSetHeaterStartTempCopy = fvalue;
    m_fSetHeaterStopTemp = fvalue;        //加热器停止温度
    m_fSetHeaterStopTempCopy = fvalue;
    m_fSetHeaterDiffTemp = fvalue;        //加热器回差温度
    m_fSetHeaterDiffTempCopy = fvalue;

    m_fSetDryerStartHumi = fvalue;        //除湿器启动湿度
    m_fSetDryerStartHumiCopy = fvalue;
    m_fSetDryerStopHumi = fvalue;         //除湿器停止湿度
    m_fSetDryerStopHumiCopy = fvalue;
    m_fSetDryerDiffHumi = fvalue;         //除湿器回差湿度
    m_fSetDryerDiffHumiCopy = fvalue;
    m_fSetFanStartTemp = fvalue;          //排风启动温度
    m_fSetFanStartTempCopy = fvalue;
    m_fSetFanStopTemp = fvalue;           //排风停止温度
    m_fSetFanStopTempCopy = fvalue;

    m_fSetFanDiffTemp = fvalue;           //排风回差温度
    m_fSetFanDiffTempCopy = fvalue;
    m_fSetMonitorMaxTemp = fvalue;         //监控下发最大温度,单位为℃
    m_fSetMonitorMaxTempCopy = fvalue;
    m_fSetMonitorMinTemp = fvalue;         //监控下发最小温度,单位为℃
    m_fSetMonitorMinTempCopy = fvalue;
    m_fSetMonitorAvgTemp = fvalue;          //监控下发平均温度,单位为℃
    m_fSetMonitorAvgTempCopy = fvalue;
    m_fSetVolAlarmUpLimit = fvalue;       //电压告警高限,单位为V
    m_fSetVolAlarmUpLimitCopy = fvalue;

    m_fSetVolAlarmDownLimit = fvalue;     //电压告警低限,单位为V
    m_fSetVolAlarmDownLimitCopy = fvalue;
    for (int i = 0; i < ARRAYSIZE(m_fSetData); ++i)
    {
        m_fSetData[i] = fvalue;
    }

    for (int i = 0; i < ARRAYSIZE(m_fSetDataCopy); ++i)
    {
        m_fSetDataCopy[i] = fvalue;
    }

    m_uSetCtrlTempType = uvalue;        //设置控温方式
    m_uSetCtrlTempTypeCopy = uvalue;
    m_uSetCtrlHumiType = uvalue;        //设置控湿方式
    m_uSetCtrlHumiTypeCopy = uvalue;
    m_uSetCtrlTempManualSwitch = uvalue; //设置控温手动开关
    m_uSetCtrlTempManualSwitchCopy = uvalue;
    m_uSetCtrlHumiManualSwitch = uvalue; //设置控湿手动开关
    m_uSetCtrlHumiManualSwitchCopy = uvalue;
    for (int i = 0; i < ARRAYSIZE(m_uSetData); ++i)
    {
        m_uSetData[i] = uvalue;
    }

    for (int i = 0; i < ARRAYSIZE(m_uSetDataCopy); ++i)
    {
        m_uSetDataCopy[i] = uvalue;
    }
}
